package com.dzsw.mustache;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;

import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;

public class MustacheExample {
    public static void main(String[] args) throws IOException {
        // 创建 Mustache 工厂
        MustacheFactory mf = new DefaultMustacheFactory();
        // 加载模板
        Mustache mustache = mf.compile("template.mustache");
        // 准备数据模型
        Map<String, Object> context = new HashMap<>();
        context.put("name", "Mustache");
        context.put("language", "Java");
        // 渲染模板
        StringWriter writer = new StringWriter();
        mustache.execute(writer, context).flush();
        // 输出结果
        System.out.println(writer.toString());
    }
}